# coding=utf-8
import requests,re
"""
使用高德地图api 懒得处理数据正则直接匹配QaQ
网络不好不调用
"""
class Api():
	def __init__(self):
		self.__head = {
			'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0'}
	def Gd(self,dm):
		head = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0'}
		try:

			url = 'http://ditu.amap.com/service/poiInfo?query_type=TQUERY&pagesize=20&pagenum=1&qii=true&cluster_state=5&need_utd=true&utd_sceneid=1000&div=PC1000&addr_poi_merge=true&is_classify=true&zoom=12&city=500000&geoobj=106.383082%7C29.456058%7C106.736705%7C29.616163&keywords='+str(dm)
			print url
			n = requests.get(url=url,headers=self.__head,timeout=10)
			dist = n.text
			print dist
			dmbm = re.findall(r'"diner_flag":"0","id":"(.*?)","name":',dist,re.M)
			print dmbm[0] #地图编号
			#
			dz = requests.get(url='http://ditu.amap.com/detail/get/detail?id=%s' % dmbm[0], headers=self.__head, timeout=10)
			dzz = dz.text
			d = re.findall(r'address":"(.*?)"',dzz,re.M)
			print d[0]#物理地址
		except Exception,e:
			print e
a = Api()
a.Gd('重庆市长寿区人民政府')